<template>
	<view class="">
		<view class=" plr15">
			<view class="align-center justify-between bdbe" @click="changeLang(index)"
				v-for="(item,index) in languageList" :key="index">
				<view class="ft16 ptb15 "><text>{{item.title}}</text></view>
				<view v-if="active==index">
					<image src="../../static/images/mine/icon/success.png" style="width: 40rpx;height: 40rpx;"></image>
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				languageList: [{
					title: '简体中文',
					lang: 'zh'
				}, {
					title: '繁体中文',
					lang: 'hk'
				}, {
					title: 'English',
					lang: 'en'
				}, ],
				active: 0
			}
		},
		onLoad() {
			console.log(uni.getStorageSync('lang') != '')
			if (uni.getStorageSync('lang') != '') {
				let lang = uni.getStorageSync('lang').lang
				this.languageList.forEach((item, index) => {
					console.log(lang)
					if (lang == item.lang) {
						this.active = index
					}
				})
			}
		},
		methods: {
			changeLang(index) {
				this.active = index
				uni.setStorageSync('lang', this.languageList[index])
				this.$i18n.locale = this.languageList[index].lang;
				uni.setStorageSync("mescroll-i18n",  this.languageList[index].lang)
				this.$store.dispatch('changecLang')
			},
		}
	}
</script>

<style>
	page {
		background-color: #ffffff;
	}
</style>